// pages/activity/nationalDay/activeFriend/activeFriend.js
import {
  getFriendList
} from '../../../../api/activity'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentPage: 1,
    showCount: 10,
    totalPage: 1,
    friendList: [],
    canShare: false, // 是否拥有分享功能
    unActiveFriendLen: 0,
    totalScore: '0',
    toView: ''
    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.initFriendList()
  },


  openWx(e) {
    let {phone} = e.currentTarget.dataset
    if(!phone){
      return ;
    }
    wx.makePhoneCall({
      phoneNumber:phone,
      fail: (err) => {
        console.log(err)
        wx.setClipboardData({
          data: phone
        })
        wx.showToast({
          title: "好友手机号已复制，快到微信激活他吧",
          icon: 'none'
        })
      }
    })
  },
  initFriendList() {
    const {currentPage,
      showCount, } = this.data
    getFriendList({
      currentPage,
      showCount,
    }).then((res) => {
        console.log(res)
        const {
          list
        } = res.data
        let params = {}
        params.friendList = this.data.friendList.concat(list)
        params.totalPage = res.data.totalPage
        params.currentPage =   this.data.currentPage +  1 
        params.unActiveFriendLen = res.data.totalResult||0
        params.totalScore =  params.unActiveFriendLen * 1000
        this.setData(params)
      })
      .catch((err) => {
        console.warn(err)
      })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom(){
    const { currentPage , totalPage} = this.data
    if(totalPage > currentPage){
      this.initFriendList()
    }
    else{
      wx.showToast({
        title:'没有更多了',
        icon: 'none'
      })
    }
  },
})